#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      bmw39
#
# Created:     15/12/2011
# Copyright:   (c) bmw39 2011
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import pickle

def get_Target(learned_data,features):
    """

        Currently useless b/c w and b are calculated to include denormalizing
        means[0] and stdvs[0] corresponds to that of tagets
    """
    (means,stdvs,weights,b) = learned_data
    pred = b
    for i,f in enumerate(features):
        pred += (f-means[i+1])/stdvs[i+1]*weights[i]
    pred = pred*stdvs[0]+means[0]
    return pred

def main():

    #read in normalization constants
    infile = open('norm_const')
    line = infile.readline()
    #numVec = int(line[1:])

    line = infile.readline()
    numFeat = int(line[1:])

    line = infile.readline()
    tok = line.split()
    target_data = tok[0].split(',')
    target_mean = float(target_data[0])
    target_stdv = float(target_data[1])
    label_mean = []
    label_stdv = []
    for j in range(0, numFeat):
        label_value = tok[j+1].split(':')
        label_data = label_value[1].split(',')
        label_mean.append(float(label_data[0]))
        label_stdv.append(float(label_data[1]))
    print label_mean

    b = 0.14647851 # from model hardcoded

    infile.close
    weight_denorm = []
    b_denorm = target_mean + target_stdv * b
    infile = open('features_norm_rand_no_b_weights.txt')
    for j in range(0, numFeat):
        line = infile.readline()
        tok = line.split(':')
        weight_denorm.append(float(tok[1])*target_stdv/label_stdv[j])
        b_denorm += float(tok[1])*target_stdv/label_stdv[j]*label_mean[j]
    print weight_denorm
    print b_denorm



    """
        Pickling for other use, kinda useless now

    outfile = open('learned_data','w')

    results = (label_mean,label_stdv,weight,0)
    pickle.dump(results,outfile)
    outfile.close()
    """



if __name__ == '__main__':
    main()
